-
Notifications
You must be signed in to change notification settings - Fork 979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
π€π§βπ¬ [Experiment] Add Terraform Plugin Framework Code Generator #2355
base: main
Are you sure you want to change the base?
Conversation
@jrhouston When i do a go generate, it does not generate any resources |
Tried to generate some Kubernetes resurces, but the resulting code does not work. The model includes a struct representing the status. When creating an instance of a kubernetes resource, usually the status is not include in its specification (it is optional and computed). So Terraform attempts to set it as unknown. Also the manifest tags associated to each field in the generated structures have case issues. If the kubernetes resource contains an attribute named MyDHCP, the manifest entry is set to MyDhcp, thus creating a mismatch during the marshal and unmarshal processes. The terraform openapi generator generates the correct structures, with types and values for every SingleNestedAttribute. But it is unable to add the manifest attribute that allows to map the openapi specification of the kuberntes resource to the generated model. @jrhouston is there any plan to improve this pull request to have the generator generate better code? Mapping from kubernetes client structure to the terraform models generated by the openapi generator is really tedious |
Thanks for pulling down the branch and trying this out @randomswdev. This is very much a draft where my goal was to generate a simple resource like ConfigMap. Using this for large resources with spec and status certainly won't work yet βΒ I have a long todo list of things to fix to make this work.
Yep, a mechanism for supporting custom types is on my todo list.
Yeah, this is annoying. I suspect we're going to add a mechanism in the openapi generator tool to give us the OpenAPI context for the attribute so we can access the field name. If we can't do that then likely we'll need a way of configuring a known list of acronyms so cases such as your DHCP example don't get mangled.
Yup, the plan here is to make this generator work more generally and use it to migrate all the existing SDKv2 code to the plugin framework. After this we will look at breaking it out into it's own module that can be used to generate custom providers for Kubernetes.
Just out of interest, is there a specific use case you are dealing with that motivated you to try this PR? |
We want to automate some k8s operations that include activities on custom resources. So we need terraform providers to interact with those CRDs. We are looking for a fast and cheap way to develop these providers, and your generator appeared to be a quite easy solution. Currently we opted for leveraging the OpenAPI generator with hand written code for mapping the generated models back and forth to the k8s API client structures. If the future direction will be to extend the OpenAPI generator and the terraform plugin framework code generator to propagate "manifest" tags to the generated models, we will be able to automate also the mapping. And the need for custom code would be limited to very specific scenarios. |
go.mod
Outdated
@@ -148,3 +150,5 @@ require ( | |||
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3 // indirect | |||
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect | |||
) | |||
|
|||
replace github.com/hashicorp/terraform-plugin-codegen-kubernetes => /Users/john/dev/hashicorp/terraform-plugin-codegen-kubernetes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remember to fix this once codegen repo is public
Provides an easy to swap in namespace that will allow acceptance tests to run against _gen suffixed (codegen) resource implementations without having to rewrite or separately maintain test cases.
Handle waiter code within an afterCreate hook and enable all "dualstack" tests except generateName for documented reason.
Description
This PR adds tools to allow generating terraform-plugin-framework code for new resources using the Kubernetes OpenAPI specifications.
Acceptance tests
Output from acceptance testing:
Release Note
Release note for CHANGELOG:
References
Community Note